package com.crazyktv.wcf.android;

import android.app.Activity;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;

public class Setting extends Activity {
	private Button btnOK, btnCancel;
	private EditText txtIP, txtPort;
	private Spinner spinnerTime, spinnerLimitNum;
	private CheckBox cbLimit;

	/*@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		btnOK = (Button) findViewById(R.id.button_OK);
		btnCancel = (Button) findViewById(R.id.button_Cancel);
		txtIP = (EditText) findViewById(R.id.txt_ip);
		txtPort = (EditText) findViewById(R.id.txt_port);
		spinnerTime = (Spinner) findViewById(R.id.spinner1);
		spinnerLimitNum = (Spinner) findViewById(R.id.spinner2);
		cbLimit = (CheckBox) findViewById(R.id.checkBox1);
		ArrayAdapter<String> adapterTime = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, new String[] { "1", "2",
						"3", "4", "5", "10", "15", "20", "30" });
		// 設定下拉選單的樣式
		adapterTime
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerTime.setAdapter(adapterTime);

		// 設定項目被選取之後的動作
		ArrayAdapter<String> adapterNum = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, new String[] { "4", "5",
						"6" });
		// 設定下拉選單的樣式
		adapterNum
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerLimitNum.setAdapter(adapterNum);
		// 設定項目被選取之後的動作

		restorePrefs();
		btnOK.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				SharedPreferences settings = getSharedPreferences(
						MainActivity.appPref, 0);
				Editor editor = settings.edit();
				editor.putString(MainActivity.appPrefIP, txtIP.getText()
						.toString());
				editor.putString(MainActivity.appPrefPort, txtPort.getText()
						.toString());
				editor.putInt(MainActivity.appPrefRefreshTime, Integer
						.valueOf(spinnerTime.getSelectedItem().toString()));
				editor.putBoolean(MainActivity.appPrefLimit,
						cbLimit.isChecked());
				editor.putInt(MainActivity.appPrefLimitNum, Integer
						.valueOf(spinnerLimitNum.getSelectedItem().toString()));
				editor.commit();
				finish();
			}
		});
		btnCancel.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				SharedPreferences settings = getSharedPreferences(
						MainActivity.appPref, 0);
				if (settings.getString(MainActivity.appPrefIP, "") == "") {
					Editor editor = settings.edit();
					editor.putString(MainActivity.appPrefIP, txtIP.getText()
							.toString());
					editor.putString(MainActivity.appPrefPort, txtPort
							.getText().toString());
					editor.putInt(MainActivity.appPrefRefreshTime, Integer
							.valueOf(spinnerTime.getSelectedItem().toString()));
					editor.putBoolean(MainActivity.appPrefLimit,
							cbLimit.isChecked());
					editor.putInt(MainActivity.appPrefLimitNum, Integer
							.valueOf(spinnerLimitNum.getSelectedItem()
									.toString()));
					editor.commit();
				}
				finish();
			}
		});
	}*/

/*	private void restorePrefs() {
		SharedPreferences settings = getSharedPreferences(MainActivity.appPref,
				0);
		String pref_ip = settings.getString(MainActivity.appPrefIP,
				(String) getText(R.string.setting_default_ip));
		String pref_port = settings.getString(MainActivity.appPrefPort,
				(String) getText(R.string.setting_default_port));
		int pref_refresh_time = settings
				.getInt(MainActivity.appPrefRefreshTime,
						Integer.valueOf((String) getText(R.string.setting_default_time)));
		boolean pref_limit = settings.getBoolean(MainActivity.appPrefLimit, true);
		int Pref_limit_num = settings.getInt(MainActivity.appPrefLimitNum,
				Integer.valueOf((String) getText(R.string.setting_default_time)
						.toString()));

		switch (pref_refresh_time) {
		case 1:
			spinnerTime.setSelection(0);
			break;
		case 2:
			spinnerTime.setSelection(1);
			break;
		case 3:
			spinnerTime.setSelection(2);
			break;
		case 4:
			spinnerTime.setSelection(3);
			break;
		case 10:
			spinnerTime.setSelection(5);
			break;
		case 15:
			spinnerTime.setSelection(6);
			break;
		case 20:
			spinnerTime.setSelection(7);
			break;
		case 30:
			spinnerTime.setSelection(8);
			break;
		default:
			spinnerTime.setSelection(4);
		}
		switch (Pref_limit_num) {
		case 4:
			spinnerLimitNum.setSelection(0);
			break;
		case 6:
			spinnerLimitNum.setSelection(2);
			break;
		default:
			spinnerLimitNum.setSelection(1);
		}
		if (pref_ip.equals("")) {
			Toast.makeText(Setting.this, R.string.toast_server_empty,
					Toast.LENGTH_SHORT).show();
		} else {
			txtIP.setText(pref_ip);
			txtPort.setText(pref_port);
			//cbLimit.setChecked(pref_limit);
		}
	}*/
}
